<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"
>
<head>
    <!-- 设置页面的 基本路径，页面所有资源引入和页面的跳转全部基于 base路径 -->
    <base th:href="${#request.getContextPath()}+'/'">
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="Bookmark" href="/favicon.ico">
    <link rel="Shortcut Icon" href="/favicon.ico"/>

    <script type="text/javascript" th:src="@{/lib/html5shiv.js}"></script>
    <script type="text/javascript" th:src="@{/lib/respond.min.js}"></script>
    <link rel="stylesheet" type="text/css" th:href="@{/h-ui/css/H-ui.min.css}"/>
    <link rel="stylesheet" type="text/css" th:href="@{/h-ui.admin/css/H-ui.admin.css}"/>
    <link rel="stylesheet" type="text/css" th:href="@{/lib/Hui-iconfont/1.0.8/iconfont.css}"/>
    <link rel="stylesheet" type="text/css" th:href="@{/h-ui.admin/skin/default/skin.css}" id="skin"/>
    <link rel="stylesheet" type="text/css" th:href="@{/h-ui.admin/css/style.css}"/>
    <link rel="stylesheet" type="text/css" th:href="@{/lib/bootstrap/css/bootstrap.css}"/>
    <link rel="stylesheet" type="text/css" th:href="@{/lib/bootstrap-table/bootstrap-table.css}"/>
    <link rel="stylesheet" type="text/css" th:href="@{/lib/font-awesome-4.7.0/css/font-awesome.min.css}"/>

    <script type="text/javascript" th:src="@{/lib/DD_belatedPNG_0.0.8a-min.js}"></script>
    <script>DD_belatedPNG.fix('*');</script>

    <title>挂号列表管理</title>
</head>
<body>
<nav class="breadcrumb" style="margin-bottom: 5px"><i class="fa fa-cog"></i> 挂号列表管理 <span
        class="c-gray en">&gt;</span> 挂号管理 <span class="c-gray en">&gt;</span> 挂号列表
</nav>
<div class="page-container" style="padding: 0 20px">


    <div id="operateDiv" style="display: none;">
        <shiro:hasPermission name="patients:delete">
            <a title="删除" href="javascript:;" id="patients_delete" value="" onclick="patients_del(this)" class="ml-5"
               style="text-decoration:none"><i class="Hui-iconfont"></i></a>
        </shiro:hasPermission>
    </div>

    <table id="dataTable" class="table table-border table-bordered table-bg">
    </table>
</div>
<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" th:src="@{/lib/jquery/1.11.3/jquery.min.js}"></script>
<script type="text/javascript" th:src="@{/lib/layer/2.4/layer.js}"></script>
<script type="text/javascript" th:src="@{/h-ui/js/H-ui.min.js}"></script>
<script type="text/javascript" th:src="@{/h-ui.admin/js/H-ui.admin.js}"></script> <!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" th:src="@{/lib/My97DatePicker/4.8/WdatePicker.js}"></script>
<script type="text/javascript" th:src="@{/lib/datatables/1.10.0/jquery.dataTables.min.js}"></script>
<script type="text/javascript" th:src="@{/lib/bootstrap-table/bootstrap-table.js}"></script>
<script type="text/javascript" th:src="@{/lib/bootstrap-table/bootstrap-table-zh-CN.min.js}"></script>


<script type="text/javascript">
    $(function () {
        $('#dataTable').bootstrapTable({
            detailView: true,//+显示详情
            url: 'patients/list',//ajax请求的url地址
            pagination: true,
            toolbar: "#toolbar",//顶部显示的工具条（添加和批量删除的）
            contentType: 'application/x-www-form-urlencoded',//条件搜索的时候ajax请求给后台数据的数据类型（条件搜索post提交必须设置）
            search: true,//是否显示搜索框
            pageNumber: 1,//默认的页面 第一页
            pageSize: 10,//默认的每页条数
            pageList: [10, 15, 50, 100],//每页能显示的条数
            sidePagination: "server",//是否是服务器分页，每次请求都是对应的10条数据，下一页发送ajax请求
            paginationHAlign: 'right', //底部分页条
            showRefresh: true, //是否显示刷新按钮
            columns: [ //表格显示数据对应的表头设置，
                // {checkbox: true},//是否显示前台的复选框（多选）
                /*
                    每列数据的表头的设置
                    filed:返回json数据对应数据的key
                    title:表头要显示的名
                */
                [
                    {
                        "title": "患者信息",
                        "halign": "center",
                        "align": "center",
                        "colspan": 9
                    }
                ],
                [
                    {field: 'patientsId', title: '编号'},
                    {field: 'patientsName', title: '患者姓名'},
                    {field: 'patientsAge', title: '年龄'},
                    {field: 'patientsGender', title: '性别'},
                    {field: 'patientsIdcard', title: '身份证'},
                    {field: 'patientsAddress', title: '地址'},
                    {field: 'patientsAllergy', title: '过敏史'},
                    {field: 'patientsPhone', title: '电话'},
                    //操作列的设置（删除，修改）
                    /*
                    formatter: 格式化这一行，回调一个函数
                    */
                    {
                        field: 'patientsId',
                        title: '操作',
                        align: 'center',
                        formatter: getOperateBtns

                    }]],
            queryParams: function (params) {
                //此方法在用户分页或者搜索的时候回自动发送ajax请求调用，并把对应的参数传递给后台
                return {
                    pageNum: params.offset / params.limit + 1, //页码
                    pageSize: params.limit, //页面大小
                    keyword: params.search
                };
            },
            onExpandRow: function (index, row, $detail) {
                //获取当前展开行对应的 订单id
                var patientsId = row.patientsId;

                //创建一个表格，用户点击+号时候马上创建一个表格（子表），用于添加详细数据
                var cur_table = $detail.html('<table style="display: table" id="first"></table><table id="last"></table>').find('table');
                $("#first").bootstrapTable({
                    url: 'patients/detail',
                    method: 'get',
                    contentType: 'application/json;charset=UTF-8',//这里我就加了个utf-8
                    dataType: 'json',
                    queryParams: {patientsId: patientsId},
                    pageSize: 10,//默认的每页条数
                    pagination: true,//显示分页条
                    columns: [
                        [
                            {
                                "title": "患者病历",
                                "halign": "center",
                                "align": "center",
                                "colspan": 7
                            }
                        ],
                        [
                            {
                                field: 'patientsCasesId',
                                title: '序号'
                            }, {
                            field: 'morbidityDate',
                            title: '发病日期'
                        }, {
                            field: 'transmission',
                            title: '是否传染'
                        }, {
                            field: 'caseTitle',
                            title: '主诉'
                        }, {
                            field: 'caseResult',
                            title: '病状'
                        }, {
                            field: 'doctorTips',
                            title: '医生建议'
                        }, {
                            field: 'caseDesc',
                            title: '备注'
                        }
                        ]]
                });

                $("#last").bootstrapTable({
                    detailView: true,
                    url: 'visitList/list',
                    method: 'get',
                    contentType: 'application/json;charset=UTF-8',//这里我就加了个utf-8
                    dataType: 'json',
                    queryParams: {patientsId: patientsId},
                    pageSize: 10,//默认的每页条数
                    pagination: true,//显示分页条
                    columns: [
                        [
                            {
                                "title": "患者处方",
                                "halign": "center",
                                "align": "center",
                                "colspan": 4
                            }
                        ],
                        [
                            {
                                field: 'caseOrderId',
                                title: '序号'
                            }, {
                            field: 'medicineRequirement',
                            title: '特殊要求'
                        }, {
                            field: 'tcmRemark',
                            title: '评价'
                        }, {
                            field: 'caseOrderNumber',
                            title: '处方单号'
                        }
                        ]],
                    onExpandRow: function (index, row, $detail) {
                        var parentId = row.caseOrderNumber;
                        var cur_table = $detail.html('<table style="display: table" id="tbA"></table> <table style="display: table" id="tbB"></table> <table style="display: table" id="tbC"></table>').find('table');
                        //第一个子表
                        $("#tbA").bootstrapTable({
                            url: 'visitList/listA',
                            method: 'get',
                            contentType: 'application/json;charset=UTF-8',//这里我就加了个utf-8
                            dataType: 'json',
                            queryParams: {parentId: parentId},
                            pageSize: 10,//默认的每页条数
                            pagination: true,//显示分页条
                            columns: [
                                {
                                    field: 'careOrderTmpId',
                                    title: '序号'
                                }, {
                                    field: 'medicineName',
                                    title: '药品名称'
                                }, {
                                    field: 'number',
                                    title: '数量'
                                }, {
                                    field: 'price',
                                    title: '单价'
                                }, {
                                    field: 'totalMoney',
                                    title: '总价'
                                }, {
                                    field: 'specialRequirements',
                                    title: '特殊要求'
                                }, {
                                    field: 'caseOrderNumber',
                                    title: '单号'
                                }
                            ]
                        })
                        $("#tbB").bootstrapTable({
                            url: 'visitList/listB',
                            method: 'get',
                            contentType: 'application/json;charset=UTF-8',//这里我就加了个utf-8
                            dataType: 'json',
                            queryParams: {parentId: parentId},
                            pageSize: 10,//默认的每页条数
                            pagination: true,//显示分页条
                            columns: [
                                    {
                                        field: 'checkId',
                                        title: '序号'
                                    }, {
                                    field: 'checkName',
                                    title: '检查名称'
                                }, {
                                    field: 'checkMoney',
                                    title: '价钱'
                                }, {
                                    field: 'checkCost',
                                    title: '成本'
                                }, {
                                    field: 'caseOrderNumber',
                                    title: '单号'
                                }
                                ]
                        })
                        $("#tbC").bootstrapTable({
                            url: 'visitList/listC',
                            method: 'get',
                            contentType: 'application/json;charset=UTF-8',//这里我就加了个utf-8
                            dataType: 'json',
                            queryParams: {parentId: parentId},
                            pageSize: 10,//默认的每页条数
                            pagination: true,//显示分页条
                            columns: [
                                    {
                                        field: 'surchargeId',
                                        title: '序号'
                                    }, {
                                    field: 'typeName',
                                    title: '药品名称'
                                }, {
                                    field: 'surchargeTypeName',
                                    title: '类型'
                                }, {
                                    field: 'surchargeMoney',
                                    title: '单价'
                                }, {
                                    field: 'caseOrderNumber',
                                    title: '单号'
                                }
                                ]
                        })
                    }
                })
            }

        });

    });


    function getOperateBtns(value, row, index) {
        var html = "";
        $("#operateDiv").find("a").each(function () {
            var myA = $(this).clone()
            myA.attr("value", row.patientsId)
            html += myA.prop("outerHTML") + "&nbsp;&nbsp;&nbsp;&nbsp;";
        });
        return html;
    }

</script>


<script type="text/javascript">


    /*管理员-编辑*/
    function patients_detailed(obj) {
        var patientsId = obj.getAttribute("value")
        layer.open({
            type: 2,
            title: '患者详细信息',
            shadeClose: true,
            shade: false,
            maxmin: true, //开启最大化最小化按钮
            area: [$(window).width() + 'px', $(window).height() + 'px'],
            content: ['patients/detailed?patientsId=' + patientsId, 'no']
        });
    }

    /*管理员-删除*/
    function patients_del(obj) {
        var patientsId = obj.getAttribute("value")
        layer.confirm('确认要删除吗？', function () {
            $.get("patients/delete?patientsId=" + patientsId, function (data) {
                //操作结果提示
                layer.msg(data.msg, {icon: data.code, time: 1000}, function () {
                    //操作成功刷新数据
                    if (data.code == 1) {
                        refresh();

                    }
                });

            })

        });
    }


    function refresh() {
        $('#dataTable').bootstrapTable('refresh');
    }


</script>
</body>
</html>
